package com.white.server.impl;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

public class ServerListen implements Runnable {
    private final Socket clientSocket;
    public ServerListen(Socket clientSocket) {
        this.clientSocket = clientSocket;
    }

    @Override
    public void run() {
        try {
            ObjectInputStream inputStream = new ObjectInputStream(clientSocket.getInputStream());
            while (true) {
                try {
                    Object o = inputStream.readObject();
                    System.out.println("接收客户端：" + o.toString());
                } catch (IOException | ClassNotFoundException e) {
                    e.printStackTrace();
                }

            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (clientSocket != null) {
                try {
                    clientSocket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
